package site.wanjiahao;

import site.wanjiahao.printer.BinaryTrees;

import javax.swing.tree.TreeNode;
import java.util.Random;
import java.util.function.Consumer;

public class Main {

    /**
     *    6
     *  3   7
     *2  5
     * @param args
     */
    public static void main(String[] args) {

        Integer[] ins = new Integer[]{5, 3, 8, 1, 4, 6, 9, 2, 7};

        BinarySearchTree<Integer> binarySearchTree = new BinarySearchTree<>();

        for (Integer in : ins) {
            binarySearchTree.add(in);
        }


        BinaryTrees.print(binarySearchTree);

        System.out.println();
    }


    private static void extracted2() {
        BinarySearchTree<Integer> binarySearchTree = new BinarySearchTree<>();

        for (int i = 0; i < 20; i++) {
            int random = new Random().nextInt(100);
            binarySearchTree.add(random);
        }

        BinaryTrees.print(binarySearchTree);


        System.out.println();
        System.out.println(binarySearchTree.height());
        System.out.println(binarySearchTree.isComplete());
    }

    private static void extracted1() {
        Integer[] ins = new Integer[]{7, 4, 9, 2, 5, 8, 11, 1, 3, 10, 12};

        BinarySearchTree<Integer> binarySearchTree = new BinarySearchTree<>();

        for (Integer in : ins) {
            binarySearchTree.add(in);
        }

        System.out.println(binarySearchTree);
    }

    private static void extracted() {
        Integer[] ins = new Integer[]{7, 4, 9, 2, 5, 8, 11, 3, 12, 1};

        BinarySearchTree<Integer> binarySearchTree = new BinarySearchTree<>();

        for (Integer in : ins) {
            binarySearchTree.add(in);
        }


        binarySearchTree.preorderTraversal(new BinarySearchTree.Consumer<Integer>() {
            @Override
            boolean accept(Integer integer) {
                if (integer == 1) return true;
                System.out.print(integer + ", ");
                return false;
            }
        });

        System.out.println();


        binarySearchTree.inorderTraversal(new BinarySearchTree.Consumer<Integer>() {
            @Override
            boolean accept(Integer integer) {
                if (integer == 4) return true;
                System.out.print(integer + ", ");
                return false;
            }
        });
        System.out.println();


        binarySearchTree.postorderTraversal(new BinarySearchTree.Consumer<Integer>() {
            @Override
            boolean accept(Integer integer) {
                if (integer == 5) return true;
                System.out.print(integer + ", ");
                return false;
            }
        });

        System.out.println();

        binarySearchTree.levelOrderTraversal(new BinarySearchTree.Consumer<Integer>() {
            @Override
            boolean accept(Integer integer) {
                if (integer == 2) return true;
                System.out.print(integer + ", ");
                return false;
            }
        });
    }
}
